package com.ruoyi.enterprise.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.enterprise.domain.ComEvent;
import com.ruoyi.enterprise.service.IComEventService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 重大事件Controller
 * 
 * @author ruoyi
 * @date 2024-03-15
 */
@RestController
@RequestMapping("/enterprise/event")
public class ComEventController extends BaseController
{
    @Autowired
    private IComEventService comEventService;

    /**
     * 查询重大事件列表
     */
    @PreAuthorize("@ss.hasPermi('enterprise:event:list')")
    @GetMapping("/list")
    public TableDataInfo list(ComEvent comEvent)
    {
        startPage();
        List<ComEvent> list = comEventService.selectComEventList(comEvent);
        return getDataTable(list);
    }

    /**
     * 导出重大事件列表
     */
    @PreAuthorize("@ss.hasPermi('enterprise:event:export')")
    @Log(title = "重大事件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ComEvent comEvent)
    {
        List<ComEvent> list = comEventService.selectComEventList(comEvent);
        ExcelUtil<ComEvent> util = new ExcelUtil<ComEvent>(ComEvent.class);
        util.exportExcel(response, list, "重大事件数据");
    }

    /**
     * 获取重大事件详细信息
     */
    @PreAuthorize("@ss.hasPermi('enterprise:event:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(comEventService.selectComEventById(id));
    }

    /**
     * 新增重大事件
     */
    @PreAuthorize("@ss.hasPermi('enterprise:event:add')")
    @Log(title = "重大事件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ComEvent comEvent)
    {
        return toAjax(comEventService.insertComEvent(comEvent));
    }

    /**
     * 修改重大事件
     */
    @PreAuthorize("@ss.hasPermi('enterprise:event:edit')")
    @Log(title = "重大事件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ComEvent comEvent)
    {
        return toAjax(comEventService.updateComEvent(comEvent));
    }

    /**
     * 删除重大事件
     */
    @PreAuthorize("@ss.hasPermi('enterprise:event:remove')")
    @Log(title = "重大事件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(comEventService.deleteComEventByIds(ids));
    }
}
